home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / dev / lang / J4thDemo.lha / Tutorials / Grand_Tour < prev    next >
Encoding:
Text File  |  1992-09-08  |  6.7 KB  |  183 lines

  1.  
  2.                      GRAND TOUR OF JFORTH
  3.     
  4.     The section describes some of the special features of 
  5.     JForth.  If you have never used any Forth, you may want to 
  6.     try the tutorial first.  
  7.     
  8.     Let's start with a grand tour of the main JForth tools.  
  9.     Bring up the JForth demo and try out these commands as we 
  10.     discuss them.  (If you are unclear about how to read stack 
  11.     diagrams, please try the tutorial first.)  
  12.     
  13.     WORDS-LIKE ( <word-fragment> -- , list all with fragment )  
  14.     
  15.     Use this if you want to see all of the words that have some 
  16.     word fragment in their name.  ENTER:  
  17.     
  18.         WORDS-LIKE  EMIT  ( all words with EMIT ) 
  19.         WORDS-LIKE  +     ( all words with '+' ) 
  20.     
  21.     As a shortcut, if you hit <Function-Key-6> it will insert 
  22.     WORDS-LIKE into your input stream.  This will save you from 
  23.     having to type it in.  Hit the <HELP> key to find out about 
  24.     other function key assignments.  Now hit the <Up-Arrow> key 
  25.     repeatedly to scroll through your previous commands just 
  26.     like in the Amiga DOS shell.  You can look in the section on 
  27.     Command Line History for more information about this.   
  28.     
  29.     WORDS ( -- , list the words currently available )  
  30.     
  31.     This command lists the words in the dictionary that you can 
  32.     call.  Although thousands of words may be listed, you will 
  33.     only need to learn a few.  You can stop the output of this 
  34.     list by hitting a key.  Hit return to continue listing or 
  35.     enter "quit" to stop.  You could also enter a Forth command 
  36.     while WORDS is paused.  This pause feature is provided by 
  37.     ?PAUSE which is described in the glossary.  VLIST is a 
  38.     synonym for WORDS.   
  39.     
  40.     DEF  ( <name> -- , disassemble word )  
  41.     
  42.     Here is a handy word for those of you who are familiar with 
  43.     68000 assembly language.  DEF will disassemble any Forth 
  44.     word.  ENTER:
  45.     
  46.         DEF 1+ 
  47.         DEF CMOVE 
  48.     
  49.     In the release version of JForth, the first time you enter 
  50.     DEF it will load a precompiled MODULE containing the 
  51.     disassembler.  This gives you quick access to DEF without 
  52.     taking up room in the dictionary or having to compile it 
  53.     yourself.
  54.     
  55.     DOS  ( <command-line> -- , pass command to Amiga DOS )  
  56.     
  57.     You can execute almost any Amiga DOS command line except 
  58.     those that require input, and CD.  For CD, just enter CD 
  59.     without using the DOS keyword (CD has been provided for you 
  60.     in the JForth dictionary).  Some common DOS commands have 
  61.     been predefined.
  62.     
  63.     Let's execute a DOS command.  ENTER:
  64.     
  65.         DOS TYPE S:STARTUP-SEQUENCE OPT H
  66.         
  67.     For CD, use CD directly.  
  68.     
  69.         CD RAM: 
  70.     
  71.     Use predefined command.  
  72.     
  73.         DIR DF0: 
  74.     
  75.     Pass command in string.  
  76.     
  77.         " RENAME RAM:MOO RAM:GOO"  $DOS
  78.         
  79.     MEASURE ( <Forth-line> -- , time Forth commands )
  80.     
  81.     This is handy when you are trying to speed up your code.  
  82.     This command will tell you how long things take.  It will 
  83.     take the commands that follow, execute them and tell you how 
  84.     long it took.   
  85.     
  86.         MEASURE DIR 
  87.     
  88.     BENCH  ( <Forth-line> -- , time commands with overhead )  
  89.     
  90.     MEASURE and BENCH are only accurate to about 1/50th of a 
  91.     second.  If something takes less than 1/2 a second you 
  92.     should call it N times in a loop then divide by N to find 
  93.     out the actual time.  If you want to take the loop overhead 
  94.     into account, use BENCH and BENCH.WITH.   
  95.     
  96.         : TDO  ( N -- ) 
  97.             0 DO LOOP 
  98.         ; 
  99.         : TSWAP ( a b count -- a b | b a ) 
  100.             0 DO SWAP LOOP 
  101.         ; 
  102.         1,000,000 BENCH.WITH TDO 
  103.         11 22 33 1,000,000 BENCH TSWAP
  104.         
  105.     INCLUDE ( <filename> -- , compile source code from a file)
  106.     
  107.     You can specify a complete pathname or use the current 
  108.     directory.  INCLUDE can be nested so you can call INCLUDE in 
  109.     the file you are currently INCLUDEing.  (See INCLUDE? in the 
  110.     glossary.) INCLUDE is a very important word so we have 
  111.     assigned it to <Function-Key-1>.   
  112.     
  113.         INCLUDE JU:RANDOM 
  114.         6 CHOOSE .  ( random number, 0 <= R < 5 ) 
  115.         6 CHOOSE .  
  116.     
  117.         TYPEFILE JU:LOGTO 
  118.         MEASURE INCLUDE JU:LOGTO
  119.         
  120.     JForth uses a HASHED dictionary to speed up compilation.  
  121.     This is a special way of looking words up directly instead 
  122.     of scanning the entire dictionary. If we turn off hashing we 
  123.     can see how hashing speeds up the compile process...   
  124.     
  125.         HASH.OFF 
  126.         MEASURE INCLUDE JU:LOGTO
  127.         
  128.     Notice how compilation is slower without hashing.  Hashing 
  129.     does not, however, come without a price.  JForth has to 
  130.     build a table of pointers for hashing to work. This 
  131.     rehashing is required whenever you FORGET code or do a 
  132.     GETMODULEs.  If we recompile LOGTO with hashing on we will 
  133.     have to rehash.   
  134.     
  135.         HASH.ON 
  136.         MEASURE INCLUDE JU:LOGTO
  137.         
  138.     This is still faster than compiling with hashing off.  
  139.     Hashing is most effective with large files when the 
  140.     dictionary has lots of words already defined.  Some people 
  141.     have reported an 8-9 times speed up.  Hashing is least 
  142.     effective when you recompile small files but they are pretty 
  143.     fast anyway. Hashing will speed up compilation in almost 
  144.     every instance so we usually leave it on.
  145.     
  146.     MAP ( -- , display system status )  
  147.     
  148.     This word tells you all about the current system, how many 
  149.     files are open, how much room is left in the dictionary, 
  150.     etc.  This is assigned to a function key.  Hit <HELP> to 
  151.     find out which one.   
  152.     
  153.     FILE? ( <name> -- , show file and source code )  
  154.     
  155.     If you are curious about how a word is defined you can use 
  156.     FILE? to see what file it is from.  It will then ask you if 
  157.     you want to see everywhere it is referenced or defined in 
  158.     that file. [Note: The demo version will not show you the 
  159.     source code to the pre-compiled JForth words, because the 
  160.     source files are not included.  In the normal release, 
  161.     almost all of the source IS provided.]
  162.     
  163.         FILE? ANEW 
  164.     
  165.     EACH.FILE?  ( <name> -- , show every file and source code )  
  166.     
  167.     If a word has been redefined, this command will find every 
  168.     occurrence of it in the dictionary and show it to you.
  169.     
  170.         EACH.FILE?  AUTO.INIT 
  171.         EACH.FILE?  [FORGET] 
  172.     
  173.     SAVE-FORTH  ( <filename> -- , save current JForth system )
  174.     
  175.     SAVE-FORTH is disabled in the Demo Version.  SAVE-FORTH 
  176.     allows you to save a new dictionary with many files loaded 
  177.     in.  Thus you could save a dictionary withh all of the ANIM 
  178.     code precompiled.  This can save considerable time when 
  179.     working on large projects.  SAVE-FORTH also allows you to 
  180.     expand the dictionary as it saves.  This is disabled in the 
  181.     demo version so that you can not expand the available 
  182.     dictionary.
  183.